#!/bin/bash
source /etc/profile

#实时处理res_addVip_cd
dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"
yt="`date -d "$d  1 days ago "  "+%Y-%m-%d"`"
totalPeople="`mysql -uroot -proot  -e 'SELECT totalPeople from result.res_addVip_cd where date="'"$yt"'"'|awk 'NR != 1 {print $1}'`"
if [ ! -n "$totalPeople" ]
    then  totalPeople=0
fi

echo totalPeople: $totalPeople
todayPeople="`mysql -uroot -proot -hhadoop2 -e 'SELECT COUNT(CARD_ID)AS COUNT FROM oraclecd.TBL_CARD where EFFECTIVEDATE="'"$dt"'"' |awk 'NR !=1{print $1}'`"
if [ ! -n "$todayPeople" ] 
    then  todayPeople=0
fi
echo todayPeople: $todayPeople
totalPeople="`expr $totalPeople + $todayPeople`"
echo totalPeople: $totalPeople

mysql -uroot -proot -e "INSERT into result.res_addVip_cd VALUES('$dt',$todayPeople,$totalPeople) on duplicate key update number=$todayPeople,totalPeople=$totalPeople"
echo "INSERT into result.res_addVip_cd VALUES('$dt',$todayPeople,$totalPeople)"
